package online.flowerinsnow.minecraft.bukkit.manhunt.util;

import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class MessageUtils {
    public static String parseColor(String s) {
        return s == null ? null :
                s.replace("&", "§")
                .replace("§§", "&");
    }
    public static String removeColor(String s) {
        if (s == null) return null;
        StringBuilder sb = new StringBuilder(s);
        int index;
        while ((index = sb.indexOf("§")) != -1) {
            sb.delete(index, index + 1);
        }
        return sb.toString();
    }
    public static void sendMustBePlayer(CommandSender sender) {
        sender.sendMessage(parseColor("&7[&c×&7]&c您必须是一名玩家才能这么做"));
    }

    public static void sendActionBar(Player player, String message) {
        player.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(MessageUtils.parseColor(message)));
    }
}
